﻿using Amazon.SimpleDB.Model;
using ICommonLibrary;
using ICommonLibrary.Date;

namespace CsiroCloudAggregator.User.Object {
    public class AwsUserAccountHelper {

        public static AwsUserAccount CreateAwsUserAccount(Item item) {
            var account = new AwsUserAccount();
            foreach (var attribute in item.Attribute) {
                switch (attribute.Name) {
                    case AwsUserAccountAttributes.UserRole:
                        account.UserRole = Util.GetEnum(attribute.Value, AwsUserRole.Consumer);
                        break;
                    case AwsUserAccountAttributes.Email:
                        account.Email = Util.GetString(attribute.Value);
                        break;
                    case AwsUserAccountAttributes.Name:
                        account.Name = Util.GetString(attribute.Value);
                        break;
                    case AwsUserAccountAttributes.DateCreated:
                        account.DateCreated = DateUtil.ParseUtc(attribute.Value, DateUtil.Epoch);
                        break;
                    case AwsUserAccountAttributes.SecPassword:
                        account.Password = Util.GetString(attribute.Value);
                        break;
                    case AwsUserAccountAttributes.AwsAccessKey:
                        account.AwsAccessKey = Util.GetString(attribute.Value);
                        break;
                    case AwsUserAccountAttributes.AwsSecretKey:
                        account.AwsSecretKey = Util.GetString(attribute.Value);
                        break;
                }
            }
            return account;
        }
        
    }
}
